﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:s="http://schemas.microsoft.com/surface/2008"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:LoopingSurfaceListBoxControlLibrary"
    xmlns:Microsoft_Surface_Presentation_Generic="clr-namespace:Microsoft.Surface.Presentation.Generic;assembly=Microsoft.Surface.Presentation.Generic"
    >

  <!-- Style for ListBox -->
  <Style x:Key="LoopingSurfaceListBox" TargetType="{x:Type s:SurfaceListBox}">
    <Setter Property="SelectionMode" Value="Single" />
    <Setter Property="Padding" Value="5" />
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate>
          <s:SurfaceScrollViewer Background="{TemplateBinding Background}"
                                               VerticalScrollBarVisibility="Disabled"
                                               HorizontalScrollBarVisibility="Hidden"
                                            VerticalAlignment="{TemplateBinding VerticalContentAlignment}" 
                                            HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                               CanContentScroll="True">
            <local:LoopingPanel IsItemsHost="True" />
          </s:SurfaceScrollViewer>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <!-- Style for ListBoxItems -->
  <Style x:Key="LoopingSurfaceListBoxItem" TargetType="{x:Type s:SurfaceListBoxItem}">
    <Setter Property="BorderThickness" Value="0,0,0,0"/>
    <Setter Property="BorderBrush" Value="{x:Null}"/>

    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type s:SurfaceListBoxItem}">
          <ControlTemplate.Resources>
            <Storyboard x:Key="Select">
              <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="RenderOverlay" Storyboard.TargetProperty="(UIElement.Opacity)">
                <SplineDoubleKeyFrame KeyTime="00:00:00.1000000" Value="1"/>
              </DoubleAnimationUsingKeyFrames>
            </Storyboard>
            <Storyboard x:Key="Press">
              <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="surfaceShadowChrome" Storyboard.TargetProperty="(UIElement.Opacity)">
                <SplineDoubleKeyFrame KeyTime="00:00:00.1000000" Value="1"/>
              </DoubleAnimationUsingKeyFrames>
              <ThicknessAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="surfaceShadowChrome" Storyboard.TargetProperty="(FrameworkElement.Margin)">
                <SplineThicknessKeyFrame KeyTime="00:00:00.1000000" Value="-5"/>
              </ThicknessAnimationUsingKeyFrames>
            </Storyboard>
            <Storyboard x:Key="Unselect">
              <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="RenderOverlay" Storyboard.TargetProperty="(UIElement.Opacity)">
                <SplineDoubleKeyFrame KeyTime="00:00:00.5000000" Value="0"/>
              </DoubleAnimationUsingKeyFrames>
            </Storyboard>
            <Storyboard x:Key="Release">
              <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="surfaceShadowChrome" Storyboard.TargetProperty="(UIElement.Opacity)">
                <SplineDoubleKeyFrame KeyTime="00:00:00" Value="1"/>
                <SplineDoubleKeyFrame KeySpline="0.5,0.5,0.5,1" KeyTime="00:00:00.3000000" Value="0"/>
              </DoubleAnimationUsingKeyFrames>
              <ThicknessAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="surfaceShadowChrome" Storyboard.TargetProperty="(FrameworkElement.Margin)">
                <SplineThicknessKeyFrame KeyTime="00:00:00" Value="-5"/>
                <SplineThicknessKeyFrame KeySpline="0.5,0.5,0.5,1" KeyTime="00:00:00.3000000" Value="-1"/>
              </ThicknessAnimationUsingKeyFrames>
            </Storyboard>
          </ControlTemplate.Resources>
          <Grid Margin="0" MinHeight="30" MinWidth="30" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
            <Border x:Name="Item" Margin="0" Opacity="1" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="2"/>
            <Border x:Name="RenderOverlay" Opacity="0" Background="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}"/>
            <Microsoft_Surface_Presentation_Generic:SurfaceShadowChrome x:Name="surfaceShadowChrome" Margin="-1" Opacity="0" Color="White"/>
            <ContentPresenter x:Name="Content" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" IsEnabled="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Content="{TemplateBinding Content}" ContentStringFormat="{TemplateBinding ContentStringFormat}" ContentTemplate="{TemplateBinding ContentTemplate}"/>
          </Grid>
          <ControlTemplate.Triggers>

            <Trigger Property="IsSelected" Value="True">
              <Trigger.EnterActions>
                <BeginStoryboard>
                  <Storyboard>
                    <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="RenderOverlay" Storyboard.TargetProperty="(UIElement.Opacity)">
                      <SplineDoubleKeyFrame KeyTime="00:00:00.1000000" Value="1"/>
                    </DoubleAnimationUsingKeyFrames>
                  </Storyboard>
                </BeginStoryboard>
              </Trigger.EnterActions>
              <Trigger.ExitActions>
                <BeginStoryboard>
                  <Storyboard>
                    <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="RenderOverlay" Storyboard.TargetProperty="(UIElement.Opacity)">
                      <SplineDoubleKeyFrame KeyTime="00:00:00.5000000" Value="0"/>
                    </DoubleAnimationUsingKeyFrames>
                  </Storyboard>
                </BeginStoryboard>
              </Trigger.ExitActions>
            </Trigger>
            <Trigger Property="IsEnabled" Value="False">
              <Setter Property="Foreground" Value="Transparent"/>
              <Setter Property="Foreground" Value="#FF7C7C7C"/>
            </Trigger>
          </ControlTemplate.Triggers>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>
</ResourceDictionary>